//
//  SLFreeViewController.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/24.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLFreeViewController.h"
#import "SLLoginViewController.h"
#import "SLRegisterViewController.h"
#import "SLFeedTableViewCell.h"
#import "SLFreeRecommandViewController.h"
#import "SLFeedModel.h"
#import "SLNewNetMgr.h"

@interface SLFreeViewController ()

@end

@implementation SLFreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"SLFeedTableViewCell" bundle:nil] forCellReuseIdentifier:@"SLFeedTableViewCell"];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if(([VWebService isConnected] && self.shouldLoadFeed) || self.dataSorce.count == 0){
        [self loadRecommend:@"1"];
    }
}
#pragma Mark tableView 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SLFeedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SLFeedTableViewCell" forIndexPath:indexPath];
    if(cell == nil){
        cell = [[SLFeedTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SLFeedTableViewCell"];
    }
    SLFeedModel *model = self.dataSorce[indexPath.section];
    cell.titleLabel.text = model.title;
    cell.timeLabel.text = [NSString stringWithFormat:@"%@",model.time];
    cell.scoreLabel.text = model.score;
    [cell setResult:model.result];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SLFeedModel *model = (SLFeedModel *)self.dataSorce[indexPath.section];
    SLFreeRecommandViewController *vc = [[SLFreeRecommandViewController alloc]init];
    vc.feedModel = model;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
